<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>挂号记录查询</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <style>
        :root {
            --primary-color: #3b82f6;
            --secondary-color: #64748b;
            --success-color: #10b981;
            --warning-color: #f59e0b;
            --danger-color: #ef4444;
            --info-color: #06b6d4;
            --light-color: #f8fafc;
            --dark-color: #1e293b;
        }

        body {
            background-color: #f1f5f9;
            font-family: 'Inter', sans-serif;
            color: var(--dark-color);
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 2rem 1rem;
        }

        .card {
            background-color: white;
            border-radius: 0.75rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
            margin-bottom: 2rem;
            transition: transform 0.2s ease-in-out;
        }

        .card:hover {
            transform: translateY(-2px);
        }

        .card-header {
            background-color: var(--primary-color);
            color: white;
            padding: 1rem 1.5rem;
            border-radius: 0.75rem 0.75rem 0 0;
            display: flex;
            align-items: center;
        }

        .card-header h2 {
            margin: 0;
            font-size: 1.5rem;
            font-weight: 600;
        }

        .card-header i {
            margin-right: 0.75rem;
            font-size: 1.25rem;
        }

        .card-body {
            padding: 1.5rem;
        }

        .search-form {
            display: flex;
            gap: 1rem;
            margin-bottom: 1.5rem;
        }

        .search-input {
            flex: 1;
            padding: 0.75rem 1rem;
            border: 1px solid #e2e8f0;
            border-radius: 0.5rem;
            font-size: 1rem;
            transition: border-color 0.2s ease-in-out;
        }

        .search-input:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
        }

        .search-button {
            background-color: var(--primary-color);
            color: white;
            border: none;
            border-radius: 0.5rem;
            padding: 0.75rem 1.5rem;
            font-size: 1rem;
            font-weight: 500;
            cursor: pointer;
            transition: background-color 0.2s ease-in-out;
        }

        .search-button:hover {
            background-color: #2563eb;
        }

        .search-button i {
            margin-right: 0.5rem;
        }

        .result-header {
            margin-bottom: 1.5rem;
            padding-bottom: 0.75rem;
            border-bottom: 1px solid #e2e8f0;
        }

        .result-header h3 {
            margin: 0;
            font-size: 1.25rem;
            font-weight: 600;
        }

        .result-table {
            width: 100%;
            border-collapse: collapse;
        }

        .result-table th, .result-table td {
            padding: 1rem;
            text-align: left;
            border-bottom: 1px solid #e2e8f0;
        }

        .result-table th {
            background-color: #f8fafc;
            color: var(--secondary-color);
            font-weight: 600;
            text-transform: uppercase;
            font-size: 0.875rem;
            letter-spacing: 0.05em;
        }

        .result-table tbody tr {
            transition: background-color 0.2s ease-in-out;
        }

        .result-table tbody tr:hover {
            background-color: #f1f5f9;
        }

        .status-badge {
            display: inline-block;
            padding: 0.25rem 0.75rem;
            border-radius: 9999px;
            font-size: 0.875rem;
            font-weight: 500;
            text-transform: capitalize;
        }

        .status-pending {
            background-color: rgba(245, 158, 11, 0.1);
            color: var(--warning-color);
        }

        .status-confirmed {
            background-color: rgba(16, 185, 129, 0.1);
            color: var(--success-color);
        }

        .status-completed {
            background-color: rgba(59, 130, 246, 0.1);
            color: var(--primary-color);
        }

        .status-canceled {
            background-color: rgba(239, 68, 68, 0.1);
            color: var(--danger-color);
        }

        .empty-state {
            text-align: center;
            padding: 3rem 0;
            color: var(--secondary-color);
        }

        .empty-state i {
            font-size: 3rem;
            margin-bottom: 1rem;
            color: #cbd5e1;
        }

        .empty-state p {
            font-size: 1.125rem;
            margin: 0;
        }

        @media (max-width: 768px) {
            .search-form {
                flex-direction: column;
            }

            .result-table th, .result-table td {
                padding: 0.75rem;
                font-size: 0.875rem;
            }

            .status-badge {
                padding: 0.25rem 0.5rem;
                font-size: 0.75rem;
            }
        }
    </style>
</head>
<body>
<div class="container">
    <div class="card">
        <div class="card-header">
            <i class="fa fa-search" aria-hidden="true"></i>
            <h2>挂号记录查询</h2>
        </div>
        <div class="card-body">
            <!-- 搜索表单 -->
            <form th:action="@{/admin/registration/list}" method="get" class="search-form">
                <input type="number" name="patient_id" placeholder="请输入患者ID" required
                       class="search-input" />
                <button type="submit" class="search-button">
                    <i class="fa fa-search" aria-hidden="true"></i> 查询记录
                </button>
            </form>

            <!-- 显示挂号记录 -->
            <div th:if="${registrations != null and !registrations.isEmpty()}">
                <div class="result-header">
                    <h3>患者ID：<span th:text="${patient_id}" class="text-primary"></span> 的挂号记录</h3>
                </div>
                <div class="overflow-x-auto">
                    <table class="result-table">
                        <thead>
                        <tr>
                            <th>挂号ID</th>
                            <th>挂号时间</th>
                            <th>症状描述</th>
                            <th>就诊医生ID</th>
                            <th>科室</th>
                            <th>状态</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="reg : ${registrations}">
                            <td th:text="${reg.id}" class="font-medium"></td>
                            <td th:text="${#dates.format(reg.register_time, 'yyyy-MM-dd HH:mm')}"></td>
                            <td th:text="${reg.symptoms} ?: '--'"></td>
                            <td th:text="${reg.doctor_id} ?: '--'"></td>
                            <td th:text="${reg.department} ?: '--'"></td>
                            <td th:class="'status-badge ' + ${reg.status}">
                                <span th:text="${reg.status}"></span>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <div th:if="${registrations == null or registrations.isEmpty()}" class="empty-state">
                <i class="fa fa-search-minus" aria-hidden="true"></i>
                <p>请输入有效的患者ID进行查询。</p>
            </div>
        </div>
    </div>
</div>

<script>
    // 添加表单提交动画效果
    document.querySelector('form').addEventListener('submit', function(e) {
        const button = this.querySelector('button[type="submit"]');
        button.disabled = true;
        button.innerHTML = '<i class="fa fa-spinner fa-spin mr-2" aria-hidden="true"></i> 正在查询...';

        // 如果表单验证通过，才允许提交
        if (!this.checkValidity()) {
            e.preventDefault();
            e.stopPropagation();
            button.disabled = false;
            button.innerHTML = '<i class="fa fa-search mr-2" aria-hidden="true"></i> 查询记录';
        }

        this.classList.add('was-validated');
    });

    // 表格行悬停效果增强
    const tableRows = document.querySelectorAll('tbody tr');
    tableRows.forEach(row => {
        row.addEventListener('mouseenter', function() {
            this.style.transform = 'translateY(-1px)';
            this.style.boxShadow = '0 4px 6px -1px rgba(0, 0, 0, 0.1)';
            this.style.transition = 'all 0.2s ease';
        });

        row.addEventListener('mouseleave', function() {
            this.style.transform = 'translateY(0)';
            this.style.boxShadow = 'none';
        });
    });
</script>
</body>
</html>